<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Exercise 4.38(b): Linear matrix inequalities with one variable</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch04_cvx_opt_probs/html/ex_4_38.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Exercise 4.38(b): Linear matrix inequalities with one variable</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% From Boyd &amp; Vandenberghe, "Convex Optimization"</span>
<span class="comment">% Jo&euml;lle Skaf - 09/26/05</span>
<span class="comment">%</span>
<span class="comment">% Finds the optimal t that would maximize c*t while still having A - t*B</span>
<span class="comment">% positive semidefinite by solving the following SDP:</span>
<span class="comment">%           minimize    c*t</span>
<span class="comment">%               s.t.    t*B &lt;= A</span>
<span class="comment">% c can either be a positive or negative real number</span>

<span class="comment">% Generate input data</span>
randn(<span class="string">'state'</span>,0);
n = 4;
A = randn(n); A = 0.5*(A'+A); <span class="comment">%A = A'*A;</span>
B = randn(n); B = B'*B;
<span class="comment">% can modify the value of c (&gt;0 or &lt;0)</span>
c = -1;

<span class="comment">% Create and solve the model</span>
cvx_begin <span class="string">sdp</span>
    variable <span class="string">t</span>
    minimize ( c*t )
    A &gt;= t * B;
cvx_end

<span class="comment">% Display results</span>
disp(<span class="string">'------------------------------------------------------------------------'</span>);
disp(<span class="string">'The optimal t obtained is'</span>);
disp(t);
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling SDPT3: 10 variables, 1 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints =  1
 dim. of sdp    var  =  4,   num. of sdp  blk  =  1
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|2.4e+01|4.8e+00|4.0e+02| 1.219270e+01  0.000000e+00| 0:0:00| chol  1  1 
 1|0.881|0.928|2.9e+00|3.9e-01|4.2e+01|-3.750658e+00 -1.667243e+00| 0:0:00| chol  1  1 
 2|0.802|0.388|5.7e-01|2.4e-01|5.6e+00|-3.433260e+01 -1.924193e+00| 0:0:00| chol  1  1 
 3|0.046|0.553|5.4e-01|1.1e-01|5.7e+01|-9.038621e+01 -2.395546e+01| 0:0:00| chol  1  1 
 4|0.290|1.000|3.8e-01|4.9e-05|1.2e+02|-7.186488e+01 -5.499101e+01| 0:0:00| chol  1  1 
 5|0.974|1.000|9.8e-03|4.9e-06|8.3e+00|-4.455226e+01 -4.975782e+01| 0:0:00| chol  1  1 
 6|1.000|1.000|1.1e-11|1.0e-03|2.5e+00|-4.673462e+01 -4.899832e+01| 0:0:00| chol  1  1 
 7|0.986|0.987|5.3e-12|1.4e-05|3.5e-02|-4.829693e+01 -4.832847e+01| 0:0:00| chol  1  1 
 8|0.988|0.989|1.9e-12|1.6e-07|4.1e-04|-4.831872e+01 -4.831909e+01| 0:0:00| chol  1  1 
 9|0.983|0.987|6.2e-13|2.0e-09|6.5e-06|-4.831898e+01 -4.831898e+01| 0:0:00| chol  1  1 
10|0.963|0.983|5.7e-14|3.6e-11|2.2e-07|-4.831898e+01 -4.831898e+01| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 10
 primal objective value = -4.83189831e+01
 dual   objective value = -4.83189833e+01
 gap := trace(XZ)       = 2.16e-07
 relative gap           = 2.22e-09
 actual relative gap    = 2.13e-09
 rel. primal infeas     = 5.68e-14
 rel. dual   infeas     = 3.62e-11
 norm(X), norm(y), norm(Z) = 1.1e+02, 2.6e+02, 4.8e+02
 norm(A), norm(b), norm(C) = 2.8e+00, 1.2e+00, 4.1e+00
 Total CPU time (secs)  = 0.17  
 CPU time per iteration = 0.02  
 termination code       =  0
 DIMACS: 5.7e-14  0.0e+00  6.0e-11  0.0e+00  2.1e-09  2.2e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +48.354
 
------------------------------------------------------------------------
The optimal t obtained is
  -48.3540

</pre>
</div>
</body>
</html>